<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>localStorage</title>
</head>
<body>
    <h2>localStorage</h2>
    <button onclick="saveData()">点我保存数据</button>
    <button onclick="readData()">点我读取数据</button>
    <button onclick="delData()">点我删除数据</button>
    <button onclick="clearData()">点我清空数据</button>

    <script type="text/javascript">
        let p = {name: 'wjz', age: 22}

        function saveData() {
            localStorage.setItem('msg', 'Hello')
            localStorage.setItem('msg2', 666)
            localStorage.setItem('people', JSON.stringify(p))
        }

        function readData() {
            console.log(localStorage.getItem('msg'))
            console.log(localStorage.getItem('msg2'))
            console.log(JSON.parse(localStorage.getItem('people')))
        }

        function delData() {
            localStorage.removeItem('msg')
        }

        function clearData() {
            localStorage.clear()
        }
    </script>

</body>
</html>